package javaexperiment1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-09-02
 * Time:11:51
 */
public class NextDate {
    //判断是闰年的2月有29天，平年的2月有28天
    //初学现在，方法用public static
    public static int yearJudge(int year) {
        int count = 0;
        if (year % 100 != 0) {
            if (year % 4 == 0) {
                count = 1;
            }
        } else if (year % 400 == 0) {
            // System.out.println(year+"是闰年");
            count = 1;
        }
        return count;
    }

    //这个方法判断输入的年月日是否正确--可能某个月份没有30或则31日或者没有29日
    public static int judge(int year,int month, int day) {
        int yJudge=yearJudge(year);
        int fount = 0;//标识符
        if (day > 0 || day < 29) {
            fount = 1;
        } else if (day == 30) {
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                fount = 1;
            }
        } else if (day == 31) {
            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                fount = 1;
        }else if(yJudge==1&&day==29) {
            fount=1;
        } else if(yJudge==0&&day==28){
            fount=1;
        }
        return fount;
    }

        public static void main (String[]args){
            //System.in从键盘上输入
            Scanner sc = new Scanner(System.in);
            System.out.println("请分别输入年月日：");
            int year = sc.nextInt();
            int month = sc.nextInt();
            int day = sc.nextInt();
            int judge = judge(year,month, day);
            if (judge == 1) {
                System.out.println(year + "-" + month + "-" + day);
                System.out.println("明天的日期是：");
                //先判断年--闰年是29，平年是28
                int yJudge = yearJudge(year);

                //特殊情况：2月28日，30，31,12月31日
                if (month == 2) {
                    if (day == 28 || day == 29) {
                        if (yJudge == 1&&day==29) {
                           // System.out.println(year + "是闰年");
                            month++;
                            day=1;
                        } else if(yJudge==0&&day==28) {
                           // System.out.println(year + "是平年");
                            month++;
                            day = 1;
                        }else{
                            day++;
                        }
                    }
//月为30--换到下个
                } else if (month == 4 || month == 6 || month == 9 || month == 11) {
                    if (day == 30) {
                        month++;
                        day = 1;
                    } else {
                        day++;
                    }
                    //月有31--换到下一年
                } else if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                    if (month==12&&day == 31) {
                        year++;
                        month=1;
                        day = 1;
                    } else if (day == 31) {
                        month++;
                        day = 1;
                    } else {
                        day++;
                    }
                }
                System.out.println(year + "-" + month + "-" + day);

            } else {
                System.out.println("日历中没有这一天!");
                //System.out.println("请重新输入！");
            }
        }


    }

